﻿using System;
using System.Diagnostics;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using HYCodeBase.WinForm;
using HYView;
using RevitInteractiveUtility.ExternalEventManager;

namespace ArchPostprocessing.RoomDecorate
{
	[Transaction(TransactionMode.Manual)]
	public class CmdRoomDecorate : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elems)
		{
			CmdViewType types = CmdViewType.FloorPlan;
			if (SwitchView.SetUsableView(types, cmdData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			try
			{
				WindowHandle windowHandle = new WindowHandle(Process.GetCurrentProcess().MainWindowHandle);
				ExternalEventManagerSingleton.GetEventManger(false).ReSetRequest();
				CmdRoomDecorate.m_DecorateForm = new RoomDecorateForm(cmdData, windowHandle);
				CmdRoomDecorate.m_DecorateForm.Show(windowHandle);
			}
			catch (Exception ex)
			{
				msg = ex.Message;
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		internal static RoomDecorateForm m_DecorateForm;
	}
}
